#pragma once
#include "DPrismaticUniversal.h"
#include "../DWorld.h"
#include "../DVector3.h"
#include "DJointGroup.h"

namespace Skill
{
	namespace Ode
	{
		namespace Joints
		{		
			void DPrismaticUniversal::CollectManagedMemory()
			{
				_Anchor = nullptr;
				_Axis1 = nullptr;
				_Axis2 = nullptr;
				_Axis3 = nullptr;
				DJoint::CollectManagedMemory();
			}
			DPrismaticUniversal::DPrismaticUniversal(DWorld^ world , DJointGroup^ group)
				:DJoint(world,group)
			{
				dWorldID w = world? world->_This : NULL;
				dJointGroupID g = group? group->_This : NULL;
				_SetPointer(dJointCreatePU(w,g),true);
			}
			
			DVector3^ DPrismaticUniversal::Anchor::get()
			{
				if(!_Anchor)
					_Anchor = gcnew DVector3();
				dJointGetPUAnchor(_This,_Anchor->_This);
				return _Anchor;
			}
			void DPrismaticUniversal::Anchor::set(DVector3^ value)
			{
				dJointSetPUAnchor(_This,value->_This[0],value->_This[1],value->_This[2]);
			}

			void DPrismaticUniversal::SetAnchorDelta(dReal x, dReal y, dReal z, dReal dx, dReal dy, dReal dz)
			{
				dJointSetPUAnchorDelta(_This,x,y,z,dx,dy,dz);
			}
			void DPrismaticUniversal::SetAnchorDelta(DVector3^ p, DVector3^ d)
			{
				dJointSetPUAnchorDelta(_This,p->_This[0],p->_This[1],p->_This[2],d->_This[0],d->_This[1],d->_This[2]);
			}

			DVector3^ DPrismaticUniversal::Axis1::get()
			{
				if(!_Axis1)
					_Axis1 = gcnew DVector3();
				dJointGetPUAxis1(_This,_Axis1->_This);
				return _Axis1;
			}
			void DPrismaticUniversal::Axis1::set(DVector3^ value)
			{
				dJointSetPUAxis1(_This,value->_This[0],value->_This[1],value->_This[2]);
			}

			DVector3^ DPrismaticUniversal::Axis2::get()
			{
				if(!_Axis2)
					_Axis2 = gcnew DVector3();
				dJointGetPUAxis2(_This,_Axis2->_This);
				return _Axis2;
			}
			void DPrismaticUniversal::Axis2::set(DVector3^ value)
			{
				dJointSetPUAxis2(_This,value->_This[0],value->_This[1],value->_This[2]);
			}

			DVector3^ DPrismaticUniversal::Axis3::get()
			{
				if(!_Axis3)
					_Axis3 = gcnew DVector3();
				dJointGetPUAxis3(_This,_Axis3->_This);
				return _Axis3;
			}
			void DPrismaticUniversal::Axis3::set(DVector3^ value)
			{
				dJointSetPUAxis3(_This,value->_This[0],value->_This[1],value->_This[2]);
			}

			DVector3^ DPrismaticUniversal::AxisP::get(){return Axis3;}
			void DPrismaticUniversal::AxisP::set(DVector3^ value){Axis3 = value;}

			void DPrismaticUniversal::SetParam(DJointParameters parameter, dReal value)
			{
				dJointSetPUParam(_This,(int)parameter, value);
			}
			dReal DPrismaticUniversal::GetParam(DJointParameters parameter)
			{
				return dJointGetPUParam(_This,(int)parameter);
			}

			/*void DPrismaticUniversal::AddTorque(dReal torque)
			{
				dJointAddPUTorque(_This,torque);
			}*/

			dReal DPrismaticUniversal::Position::get()
			{
				return dJointGetPUPosition(_This);
			}

			dReal DPrismaticUniversal::PositionRate::get()
			{
				return dJointGetPUPositionRate(_This);
			}

			void DPrismaticUniversal::GetAngles([OutAttribute]dReal %angle1, [OutAttribute]dReal %angle2)
			{
				dReal a1,a2;
				return dJointGetPUAngles(_This,&a1,&a2);
				angle1 = a1;angle2 = a2;
			}

			dReal DPrismaticUniversal::Angle1::get()
			{
				return dJointGetPUAngle1(_This);
			}
			dReal DPrismaticUniversal::Angle1Rate::get()
			{
				return dJointGetPUAngle1Rate(_This);
			}
			dReal DPrismaticUniversal::Angle2::get()
			{
				return dJointGetPUAngle2(_This);
			}
			dReal DPrismaticUniversal::Angle2Rate::get()
			{
				return dJointGetPUAngle2Rate(_This);
			}
		}
	}
}